package org.esprit.ocm.server.metier.common.impl;

import java.io.Serializable;
import java.util.List;

import org.esprit.ocm.server.dao.common.IDao;
import org.esprit.ocm.server.metier.common.ICommonService;

/**
 * Base class for Business Services - use this class for utility methods and
 * generic CRUD methods.
 */
public class ServiceImpl<T> implements ICommonService<T> {

	/** 
	 * 
	 */
	private static final long	serialVersionUID	= 3542152567633805667L;

	protected IDao				dao					= null;

	public void setDao(IDao _dao) {
		this.dao = _dao;
	}

	public IDao getDao() {
		return dao;
	}

	public List<T> fetch() {
		return dao.findAll();
	}

	public int count() {
		return dao.count();
	}

	public void remove(int _id) {
		dao.delete(_id);
	}

	public void remove(T _o) {
		dao.delete(_o);
	}

	public T add(T _o) {
		return (T) dao.add(_o);
	}

	public T save(T _o) {
		return (T) dao.save(_o);
	}

	public Class<T> getType() {
		return getDao().getType();
	}

	public T findById(int id) {
		return (T) getDao().findById(id);
	}
}
